package com.mask.im.business.controller;
import com.mask.im.business.annotation.AesCrypto;
import com.mask.im.business.annotation.AccessBarrier;
import com.mask.im.business.annotation.OptLog;
import com.mask.im.business.model.dto.FeedbackDTO;
import com.mask.im.business.model.vo.FeedbackVO;
import com.mask.im.business.model.vo.ConditionVO;
import com.mask.im.business.common.model.PageResult;
import com.mask.im.business.common.model.RestResponse;
import com.mask.im.business.service.FeedbackService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import static com.mask.im.business.common.constant.OptTypeConstant.DELETE;
import static com.mask.im.business.common.constant.OptTypeConstant.SAVE;

@Api(tags = "反馈模块")
@RestController
public class FeedbackController{

	@Autowired
	private FeedbackService feedbackService;


	@OptLog(optType = SAVE)
	@ApiOperation("用户反馈")
	@PostMapping("/users/feedback")
	@AesCrypto
	@AccessBarrier(size = 5,limitTime = 6000)
	public RestResponse<String> saveFeedback(@RequestBody FeedbackVO feedbackVO){
		return feedbackService.saveFeedback(feedbackVO);
	}


	@ApiOperation("获取反馈列表")
	@GetMapping("/admin/feedback/list")
	public PageResult<FeedbackDTO> feedbackList(ConditionVO conditionVO){
		return feedbackService.feedbackList(conditionVO);
	}

	@ApiOperation("反馈拒绝受理")
	@PutMapping("/admin/feedback/refuseAccept/{feedbackId}")
	public RestResponse<String> refuseAccept(@PathVariable("feedbackId") Integer feedbackId,
	                                     @RequestParam("refuseReason") String refuseReason){
		return feedbackService.refuseAccept(feedbackId,refuseReason);
	}

	@ApiOperation("反馈状态的改变")
	@PutMapping("/admin/feedback/statusChanges/{feedbackId}")
	public RestResponse<String> statusChanges(@PathVariable("feedbackId") Integer feedbackId,
	                                      @RequestParam("status") Integer status){
		return feedbackService.statusChanges(feedbackId,status);
	}

	@ApiOperation("查看缘由")
	@GetMapping("/admin/feedback/reason/{feedbackId}")
	public RestResponse<String> feedbackReason(@PathVariable("feedbackId") Integer feedbackId){
		return feedbackService.feedbackReason(feedbackId);
	}

	@OptLog(optType = DELETE)
	@ApiOperation("删除反馈")
	@DeleteMapping("/admin/userFeedback/{id}")
	public RestResponse<String> delete(@PathVariable Integer id){
		return feedbackService.delete(id);
	}
}

